package com.example.demo.DBServer.thisDatabase.dao;

import com.example.demo.entity.ExecuteInformationEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExecuteInformationDao {
    /**
     * 新增
     * @param executeInformation
     */
    @Insert({"<script>"
                + "insert into t_execute_information("
                + "table_name, primary_key, max_size, "
                + "loop_interval, loop_type, start_time, "
                + "execute_type, archive_type, reserve_size, "
                + "reserve_type, reserve_column, sort_column, "
                + "sort_type, backup_deal_type, status) "
                + "values(#{info.tableName},#{info.primaryKey},#{info.maxSize},"
                + "#{info.loopInterval}, #{info.loopType}, #{info.startTime},"
                + "#{info.executeType}, #{info.archiveType}, #{info.reserveSize},"
                + "#{info.reserveType}, #{info.reserveColumn}, #{info.sortColumn},"
                + "#{info.sortType}, #{info.backupDealType}, #{info.status})"
            + "</script>"
    })
    @Options(useGeneratedKeys = true, keyProperty = "info.id", keyColumn = "id")
    Integer saveExecuteInformation(@Param("info")ExecuteInformationEntity executeInformation);

    /**
     * 根据id查询一个执行信息实体
     */
    @Select(value = {"select * from t_execute_information where id = #{id} "})
    @Results(id = "executeInformationMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "table_name", property = "tableName"),
            @Result(column = "primary_key", property = "primaryKey"),
            @Result(column = "max_size", property = "maxSize"),
            @Result(column = "loop_interval", property = "loopInterval"),
            @Result(column = "loop_type", property = "loopType"),
            @Result(column = "start_time", property = "startTime"),
            @Result(column = "execute_type", property = "executeType"),
            @Result(column = "archive_type", property = "archiveType"),
            @Result(column = "reserve_size", property = "reserveSize"),
            @Result(column = "reserve_type", property = "reserveType"),
            @Result(column = "reserve_column", property = "reserveColumn"),
            @Result(column = "sort_column", property = "sortColumn"),
            @Result(column = "sort_type", property = "sortType"),
            @Result(column = "backup_deal_type", property = "backupDealType"),
            @Result(column = "status", property = "cellCode")
    })
    ExecuteInformationEntity findOneById(@Param("id") Long id);

    /**
     * 根据表名执行信息实体集合
     */
    @Select(value = {"select * from t_execute_information where table_name = #{tableName} "})
    @ResultMap("executeInformationMap")
    List<ExecuteInformationEntity> findAllByTableName(@Param("tableName")String tableName);
}
